﻿// --------------------------------
// <copyright file="OrderService.cs" company="private">
//     Microsoft Public License (Ms-PL)
// </copyright>
// <author>Glenn</author>
// ---------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Ria;
using OpenTicket.Model;
using OpenTicket.Repositories;


namespace OpenTicket.Services
{
    /// <summary>
    /// Servicelayer for orders, orderitems
    /// </summary>    
    public class OrderService : OpenTicket.Services.IOrderService 
    {
        /// <summary>
        /// The Repository to use
        /// </summary>
        private IOrderRepository orderRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderService"/> class.
        /// </summary>
        /// <param name="orderRepository">The order repository.</param>
        public OrderService(IOrderRepository orderRepository)
        {
            this.orderRepository = orderRepository;
        }

        /// <summary>
        /// Saves the specified order.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <returns>The Saved Order</returns>
        public Model.Order Save(Model.Order order)
        {
            return this.orderRepository.Save(order);
        }

        /// <summary>
        /// Gets the order by id.
        /// </summary>
        /// <param name="orderId">The order id.</param>
        /// <returns>The Order from repository</returns>
        public Model.Order GetOrderById(Guid orderId)
        {
            return this.orderRepository.GetAllOrders().WithId(orderId).FirstOrDefault();
        }

        /// <summary>
        /// Deletes the order.
        /// </summary>
        /// <param name="order">The order.</param>
        public void DeleteOrder(Order order)
        {
            this.orderRepository.DeleteOrder(order);
        }
    }
}
